package com.ruoyi.web.controller.market.source;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.db.domain.SourceTaskInfo;
import com.ruoyi.source.service.ISourceTaskInfoService;
import com.ruoyi.web.wapper.SourceTaskInfoWapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 来源任务信息Controller
 * 
 * @author ruoyi
 * @date 2023-05-26
 */
@Controller
@RequestMapping("/source/taskinfo")
public class SourceTaskInfoController extends BaseController
{
    private String prefix = "source/taskinfo";

    @Autowired
    private ISourceTaskInfoService sourceTaskInfoService;

    @RequiresPermissions("source:taskinfo:view")
    @GetMapping("/{sourceId}")
    public String taskinfo(@PathVariable("sourceId")String Id,ModelMap map)
    {
        map.put("sourceId",Id);
        return prefix + "/taskinfo";
    }

    /**
     * 查询来源任务信息列表
     */
    @RequiresPermissions("source:taskinfo:view")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SourceTaskInfo sourceTaskInfo)
    {
        startPage();
        List<Map<String, Object>> mapList = sourceTaskInfoService.selectSourceTaskInfoListMap(sourceTaskInfo);
        mapList = new SourceTaskInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出来源任务信息列表
     */
    @RequiresPermissions("source:taskinfo:export")
    @Log(title = "来源任务信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SourceTaskInfo sourceTaskInfo)
    {
        List<SourceTaskInfo> list = sourceTaskInfoService.selectSourceTaskInfoList(sourceTaskInfo);
        ExcelUtil<SourceTaskInfo> util = new ExcelUtil<SourceTaskInfo>(SourceTaskInfo.class);
        return util.exportExcel(list, "来源任务信息数据");
    }

    /**
     * 新增来源任务信息
     */
    @GetMapping("/add/{sourceId}")
    public String add(ModelMap modelMap, @PathVariable("sourceId")String sourceId)
    {
        modelMap.put("sourceId",sourceId);
        return prefix + "/add";
    }

    /**
     * 新增保存来源任务信息
     */
    @RequiresPermissions("source:taskinfo:add")
    @Log(title = "来源任务信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SourceTaskInfo sourceTaskInfo)
    {
        return toAjax(sourceTaskInfoService.insertSourceTaskInfo(sourceTaskInfo));
    }

    /**
     * 修改来源任务信息
     */
    @RequiresPermissions("source:taskinfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SourceTaskInfo sourceTaskInfo = sourceTaskInfoService.selectSourceTaskInfoById(id);
        mmap.put("sourceTaskInfo", sourceTaskInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存来源任务信息
     */
    @RequiresPermissions("source:taskinfo:edit")
    @Log(title = "来源任务信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SourceTaskInfo sourceTaskInfo)
    {
        return toAjax(sourceTaskInfoService.updateSourceTaskInfo(sourceTaskInfo));
    }

    /**
     * 删除来源任务信息
     */
    @RequiresPermissions("source:taskinfo:remove")
    @Log(title = "来源任务信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sourceTaskInfoService.deleteSourceTaskInfoByIds(ids));
    }
}
